// pages/my/user/message/message.js
const app = getApp();
var url = app.getURL();

Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    nickName:'',
    avatarUrl:'',
    phone:"请完善手机号",

    message:{}
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //从缓存读取数据
    let that = this;
    let user = app.getGlobalUserInfo();
    if(user.cookieNickname!=null){
    that.setData({
      avatarUrl:user.cookieAvatar,
      nickName: user.cookieNickname,
    })
  }
  
  wx.request({
    url: url+'/user/app/cust/getCustomer',
    method:'GET',
    header: {// 设置请求的 header
      'content-type': 'application/json',
      token:wx.getStorageSync('cookieToken')
    },
    success:function(res){
      console.log(res)
      wx.setStorageSync('allMessage', res.data.data),
      that.setData({
        message: res.data.data,
      })
    }
  })

  // 读取全局数据
  if(app.globalData.userInfo.nickName!=null&&app.globalData.userInfo.nickName!='微信用户'){
    this.setData({
    nickName:app.globalData.userInfo.nickName,
    avatarUrl:app.globalData.userInfo.avatarUrl,
    })
  }
  },
  // 跳转到绑定页面
  pageTo({currentTarget: {dataset}}){
    // console.log(dataset);
    wx.navigateTo({
      url: dataset.url
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    },

})
